<template>
  <!-- 摄像头列表组件 -->
  <div class="allcameramain">
    <!-- 摄像头控制按钮 -->
    <div
      v-if="
        cameraInfoList &&
          cameraInfoList.controlFlag &&
          judgePermission(3, 'control')
      "
      class="cameracontrol"
    >
      <div class="controne">
        <div class="contro-m z-top" @click="startcontrol(0)">
          <i class="el-icon-caret-top"></i>
        </div>
        <div class="contro-m z-left" @click="startcontrol(2)">
          <i class="el-icon-caret-left"></i>
        </div>
        <div class="contro-m z-right" @click="startcontrol(3)">
          <i class="el-icon-caret-right"></i>
        </div>
        <div class="contro-m z-bottom" @click="startcontrol(1)">
          <i class="el-icon-caret-bottom"></i>
        </div>
        <div class="contro-m z-mirror" @click="mirrorcontrol()">
          <i class="el-icon-refresh-right"></i>
        </div>
      </div>
      <div class="controtwo">
        <div class="contro-left" @click="startcontrol(10)">
          焦距
          <i class="el-icon-plus"></i>
        </div>
        <div class="contro-right" @click="startcontrol(11)">
          焦距
          <i class="el-icon-minus"></i>
        </div>
      </div>
      <div class="controthree">
        <div class="greenbut" @click="startcontrol(8)">
          <i class="el-icon-zoom-in"></i> 放大
        </div>
        <div class="greenbut" @click="startcontrol(9)">
          <i class="el-icon-zoom-out"></i>缩小
        </div>
      </div>
    </div>
    <div v-else class="cameracontrol1">
      <!-- <div class="uncontrolsty-line">此设备不可控</div> -->
      <div class="controne">
        <div class="contro-m z-top">
          <i class="el-icon-caret-top"></i>
        </div>
        <div class="contro-m z-left">
          <i class="el-icon-caret-left"></i>
        </div>
        <div class="contro-m z-right">
          <i class="el-icon-caret-right"></i>
        </div>
        <div class="contro-m z-bottom">
          <i class="el-icon-caret-bottom"></i>
        </div>
        <div class="contro-m z-mirror">
          <i class="el-icon-refresh-right"></i>
        </div>
      </div>
      <div class="controtwo">
        <div class="contro-left">
          焦距
          <i class="el-icon-plus"></i>
        </div>
        <div class="contro-right">
          焦距
          <i class="el-icon-minus"></i>
        </div>
      </div>
      <div class="controthree">
        <div class="greenbut">
          <i class="el-icon-zoom-in"></i> 放大
        </div>
        <div class="greenbut">
          <i class="el-icon-zoom-out"></i>缩小
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import nowpagereq from "@/api/digital-production/material-link-monitoring/video-surveillance/index";
import { mapGetters } from "vuex";
import Axios from "axios";
// import axios from 'axios'
export default {
  props: {
    
  },
  data() {
    return {
      // 当前摄像头id
      cameraId: "",
      // 当前选中摄像头的详细信息
      cameraInfoList: {},
      timer: null, // 定时器
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  mounted() {},
  beforeDestroy() {
    clearTimeout(this.timer);
    this.timer = null;
    this.cameraId = "";
  },
  methods: {
    // 开始控制
    async startcontrol(i) {
      this.timer = setTimeout(() => {
        this.$emit("nowcameraurl", "timeout");
      }, 1000 * 60 * 20);
      let params = {
        cameraId: this.cameraId,
        direction: i,
        speed: 1
      };
      await nowpagereq.controlcamera(params).then(res => {
        if (res.code != 200) this.$message.error(res.msg);
      });
      setTimeout(() => {
        this.stopcontrol();
      }, 1000);
    },
    // 镜像翻转
    async mirrorcontrol() {
      this.timer = setTimeout(() => {
        this.$emit("nowcameraurl", "timeout");
      }, 1000 * 60 * 20);
      let params = {
        cameraId: this.cameraId,
        direction: 2,
        speed: 1
      };
      await nowpagereq.mirrorcamera(params);
      setTimeout(() => {
        this.stopcontrol();
      }, 1000);
    },
    // 停止控制
    stopcontrol() {
      let params = {
        cameraId: this.cameraId
      };
      nowpagereq.stopcamera(params).then(res => {
        // console.log(res)
      });
    }
  }
};
</script>
<style lang="scss" scoped>
$height: 40px;
.uncontrolsty {
  width: 100%;
  height: calc(70% - 10px);
  margin-top: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  .uncontrolsty-line {
    color: #ccc;
    font-size: 30px;
    width: 30px;
    line-height: 50px;
  }
}
.allcameramain {
  height: 100%;
  width: 100%;
}
.cameracontrol {
  width: 100%;
  height: 100%;
  margin-top: 10px;
  .controne {
    width: 100%;
    height: 65%;
    background-image: url("~@/assets/camera/ctrlBg.png");
    background-repeat: no-repeat;
    background-size: 90%;
    background-position: center;
    position: relative;
    .contro-m {
      // border: #46c357 1px solid;
      position: relative;
      width: 25%;
      height: 25%;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 40px;
      cursor: pointer;
    }
    .contro-m:hover {
      font-size: 48px;
    }
    .z-top {
      top: 10%;
      left: 37%;
    }
    .z-left {
      top: 12%;
      left: 11%;
    }
    .z-right {
      top: -13%;
      left: 63%;
    }
    .z-bottom {
      top: -10%;
      left: 37%;
    }
    .z-mirror {
      top: -63%;
      left: 37%;
    }
  }
  .controtwo {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: space-around;
    .contro-left {
      width: 48%;
      height: 100%;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      // border: #46c357 1px solid;
      background-image: url("~@/assets/camera/transformLeft.png");
      background-repeat: no-repeat;
      background-size: 70%;
      background-position: center;
      padding-right: 30px;
      cursor: pointer;
      font-size: 18px;
    }
    .contro-left:hover {
      font-size: 20px;
    }
    .contro-right {
      width: 48%;
      height: 100%;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      // border: #46c357 1px solid;
      background-image: url("~@/assets/camera/transformRight.png");
      background-repeat: no-repeat;
      background-size: 70%;
      background-position: center;
      padding-left: 30px;
      cursor: pointer;
      font-size: 18px;
    }
    .contro-right:hover {
      font-size: 20px;
    }
  }
  .controthree {
    width: 100%;
    height: 17%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .greenbut {
      width: 28%;
      height: 60%;
      background-color: rgb(132, 180, 111);
      border-radius: 5px;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      font-weight: 600;
      font-size: 22px;
      cursor: pointer;
    }
    .greenbut:hover {
      font-size: 24px;
    }
  }
}
.cameracontrol1 {
  width: 100%;
  height: 100%;
  margin-top: 10px;
  .controne {
    width: 100%;
    height: 65%;
    background-image: url("~@/assets/camera/ctrlBg.png");
    background-repeat: no-repeat;
    background-size: 90%;
    background-position: center;
    position: relative;
    mix-blend-mode: soft-light;
    .contro-m {
      // border: #46c357 1px solid;
      position: relative;
      width: 25%;
      height: 25%;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 40px;
      cursor: pointer;
    }
    .z-top {
      top: 10%;
      left: 37%;
    }
    .z-left {
      top: 12%;
      left: 11%;
    }
    .z-right {
      top: -13%;
      left: 63%;
    }
    .z-bottom {
      top: -10%;
      left: 37%;
    }
    .z-mirror {
      top: -63%;
      left: 37%;
    }
  }
  .controtwo {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: space-around;
    .contro-left {
      width: 48%;
      height: 100%;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      // border: #46c357 1px solid;
      background-image: url("~@/assets/camera/transformLeft.png");
      background-repeat: no-repeat;
      background-size: 70%;
      background-position: center;
      padding-right: 30px;
      mix-blend-mode: soft-light;
      cursor: pointer;
      font-size: 18px;
    }
    .contro-right {
      width: 48%;
      height: 100%;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      // border: #46c357 1px solid;
      background-image: url("~@/assets/camera/transformRight.png");
      background-repeat: no-repeat;
      background-size: 70%;
      background-position: center;
      padding-left: 30px;
      mix-blend-mode: soft-light;
      cursor: pointer;
      font-size: 18px;
    }
  }
  .controthree {
    width: 100%;
    height: 17%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    mix-blend-mode: soft-light;
    .greenbut {
      width: 28%;
      height: 60%;
      background-color: rgb(132, 180, 111);
      border-radius: 5px;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      font-weight: 600;
      font-size: 22px;
      cursor: pointer;
    }
  }
}
.zlistbtn {
  display: flex;
  justify-content: center;
  align-items: center;
  .btn {
    border: none !important;
    height: 100%;
  }
}
</style>
